let initData = {
    name:"zhangsan",
    arr:[],
    pushData:[] //上拉加载下拉刷新得数据
}
let antdReducer = (state=initData,action)=>{
    let newArr = JSON.parse(JSON.stringify(state.arr)) // 拷贝一份数据
    switch (action.type) {
        case "getList" :
            return {
                ...state,
                arr:action.payload
            }
        case "delFN" :
            newArr.splice(action.payload,1)
            return {
                ...state,
                arr:newArr
            }
        case "addfn" :
            action.payload.key = new Date().getTime()
            newArr.unshift(action.payload)
            return {
                ...state,
                arr:newArr
            }
        case "editFn" :
            action.payload.key = new Date().getTime()
             newArr[action.payload.editIndex] = action.payload
            return {
                ...state,
                arr:newArr
            }
        case "searchfn" :
            let newArr1 = newArr.filter((item,index)=>{
                return item.name1.includes(action.payload)
            })
            return {
                ...state,
                arr:newArr1
            }
        case "getPushList" :
            let newArr2 = action.payload
            let newArr3 = [...state.pushData,...action.payload]
            if (action.mode == "up") {
                return {
                    ...state,
                    pushData:newArr3
                }
            } else if (action.mode == "down") {
                return {
                    ...state,
                    pushData:newArr2
                }
            } else {
                return {
                    ...state,
                    pushData:newArr3
                }
            }
        case "getPullList" :
            let newArr7 = action.payload
            let newArr10 = [...state.pushData,...action.payload] // 把所有的数据都打散到新的数组中
            if (action.mode == "up") { // 上拉事件
                 return {
                     ...state,
                     pushData:newArr10
                 }
            } else if(action.mode == "down") { // 下拉
                return {
                    ...state,
                    pushData:newArr7
                }
            } else {
                return {
                    ...state,
                    pushData:newArr7
                }
            }
          
           
        default :
            return {
                ...state
            } 

    }
   
}
export default antdReducer